package com.ruoyi.slope.human.rockfall.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.slope.dataFile.domain.SlopeDataFile;
import com.ruoyi.slope.dataFile.service.ISlopeDataFileService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.slope.human.rockfall.domain.SlopeHumanRockfall;
import com.ruoyi.slope.human.rockfall.service.ISlopeHumanRockfallService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 边坡落石Controller
 * 
 * @author ruoyi
 * @date 2025-04-27
 */
@RestController
@RequestMapping("/human/rockfall")
public class SlopeHumanRockfallController extends BaseController
{    
    @Autowired
    private ISlopeDataFileService slopeDataFileService;
    @Autowired
    private ISlopeHumanRockfallService slopeHumanRockfallService;

    /**
     * 查询边坡落石列表
     */
    @PreAuthorize("@ss.hasPermi('human:rockfall:list')")
    @GetMapping("/list")
    public TableDataInfo list(SlopeHumanRockfall slopeHumanRockfall)
    {
        startPage();
        List<SlopeHumanRockfall> list = slopeHumanRockfallService.selectSlopeHumanRockfallList(slopeHumanRockfall);
        return getDataTable(list);
    }

    /**
     * 导出边坡落石列表
     */
    @PreAuthorize("@ss.hasPermi('human:rockfall:export')")
    @Log(title = "边坡落石", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SlopeHumanRockfall slopeHumanRockfall)
    {
        List<SlopeHumanRockfall> list = slopeHumanRockfallService.selectSlopeHumanRockfallList(slopeHumanRockfall);
        ExcelUtil<SlopeHumanRockfall> util = new ExcelUtil<SlopeHumanRockfall>(SlopeHumanRockfall.class);
        String path = util.exportExcel(response, list, "边坡落石数据"); 
        SlopeDataFile slopeDataFile = new SlopeDataFile();
        slopeDataFile.setFileName(path);
        slopeDataFileService.insertSlopeDataFile(slopeDataFile);
    }

    /**
     * 获取边坡落石详细信息
     */
    @PreAuthorize("@ss.hasPermi('human:rockfall:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(slopeHumanRockfallService.selectSlopeHumanRockfallById(id));
    }

    /**
     * 新增边坡落石
     */
    @PreAuthorize("@ss.hasPermi('human:rockfall:add')")
    @Log(title = "边坡落石", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SlopeHumanRockfall slopeHumanRockfall)
    {
        return toAjax(slopeHumanRockfallService.insertSlopeHumanRockfall(slopeHumanRockfall));
    }

    /**
     * 修改边坡落石
     */
    @PreAuthorize("@ss.hasPermi('human:rockfall:edit')")
    @Log(title = "边坡落石", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SlopeHumanRockfall slopeHumanRockfall)
    {
        return toAjax(slopeHumanRockfallService.updateSlopeHumanRockfall(slopeHumanRockfall));
    }

    /**
     * 删除边坡落石
     */
    @PreAuthorize("@ss.hasPermi('human:rockfall:remove')")
    @Log(title = "边坡落石", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(slopeHumanRockfallService.deleteSlopeHumanRockfallByIds(ids));
    }
}
